/**
 * @description 复制
 * @param {*} id DOM ID
 */
export function copyDomText(id) {
    console.log(id)
    const node = document.getElementById(id)
    if (node) {
        let createRange = document.createRange()
        createRange.selectNodeContents(document.getElementById(id))
        const selection = document.getSelection()
        selection.removeAllRanges()
        selection.addRange(createRange)
        document.execCommand('Copy')
        selection.removeAllRanges()
    }
}

function downloadBlob(resData, type) {
    if (resData.headers['Content-Type'] === 'application/json;charset=UTF-8') {
        this.$message.error({
            message: resData.data.msg,
        })
        return
    }
    let filename = 'file.bin'
    const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
    const matches = filenameRegex.exec(resData.headers['content-disposition'])
    if (matches != null && matches[1]) {
        filename = matches[1].replace(/['"]/g, '')
    }
    const data = resData.data
    const blob = new Blob([data], {
        type: type,
    })
    const eLink = document.createElement('a')
    eLink.download = decodeURI(filename)
    eLink.style.display = 'none'
    eLink.href = URL.createObjectURL(blob)
    document.body.appendChild(eLink)
    eLink.click()
    URL.revokeObjectURL(eLink.href)
    document.body.removeChild(eLink)
}